home *** CD-ROM | disk | FTP | other *** search
- /* © 1988-91, Bowers Development Corp. */
- /* WindowAids.c */
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Fonts.h>
- #include <Lists.h>
- #include <Menus.h>
- #include <Resources.h>
- #include <ToolUtils.h>
-
- #include "Globals.h"
-
- #include "WindowAids.h"
-
- short textJust; /* set by SetWFont */
-
- #define topLeft(r) (((Point *) &(r))[0])
-
- #pragma segment WindowAids
-
- typedef struct {
- Handle reserved;
- Rect displayRect;
- Byte itemKind;
- Byte dataLen;
- } ItemTemplate, *ItemTPtr;
-
- #define ItemTBaseSize sizeof (ItemTemplate)
-
- typedef struct {
- short maxItem;
- ItemTemplate items; /* repeated */
- } WitlTemplate, *WitlTPtr, **WitlTHndl;
-
- /*----------*/
- void GetWRect (short itemNr,
- Rect *itemRect)
- {
- WitlTHndl witlHandle;
- ItemTPtr wItemPtr;
- short I;
- short dataSize;
-
- SetRect (itemRect, 0, 0, 16, 16);
- witlHandle = (WitlTHndl) cur->witlHandle;
- if ((witlHandle != NULL)
- && (itemNr <= (**witlHandle).maxItem + 1) ) {
- wItemPtr = &(**witlHandle).items;
- for (I = 1; I <= itemNr - 1; I++) {
- dataSize = wItemPtr->dataLen + (wItemPtr->dataLen & 1);
- wItemPtr = (ItemTPtr) (((Ptr)wItemPtr) + (ItemTBaseSize + dataSize));
- } /*for*/
- *itemRect = wItemPtr->displayRect;
- }
- } /* GetWRect */
-
- /*----------*/
- typedef struct {
- short header;
- short offset;
- } ictbEntry, *ictbEntryPtr;
-
- typedef struct {
- ictbEntry item [5000];
- } WictTemplate, *WictTPtr, **WictTHndl;
-
- typedef struct {
- short fontNum;
- Style typeStyle;
- SignedByte just; /* AppMaker adition */
- short typeSize;
- RGBColor fgColor;
- RGBColor bgColor;
- short xferMode;
- } StyleData, *StyleDataPtr;
-
- /* defined in TextEdit: */
- /* doFont = 1; set font (family) number */
- /* doFace = 2; set character style */
- /* doSize = 4; set type size */
- /* doColor = 8; set color */
- /* addSize = 16; adjust type size */
-
- /* set background color */
- #define doBgColor 0x2000
-
- /* set transfer mode */
- #define doXferMode 0x4000
-
- /* set font by name */
- #define doByName 0x8000
-
- /*----------*/
- void SetWFont (short itemNr)
- {
- WictTHndl wictHandle;
- Ptr wictPtr;
- ictbEntryPtr itemPtr;
- short header;
- short offset;
- StyleDataPtr dataPtr;
- StyleData data;
- StringPtr fontPtr;
- Str255 fontName;
-
- wictHandle = (WictTHndl) cur->wictHandle;
- if (wictHandle != nil) {
- wictPtr = (Ptr) &(**wictHandle);
- itemPtr = &(**wictHandle).item [itemNr - 1];
- header = itemPtr->header;
- offset = itemPtr->offset;
- dataPtr = (StyleDataPtr) (wictPtr + offset);
- data = *dataPtr;
- if ((header & doFont) == 0) {
- data.fontNum = 0;
- } else {
- if ((header & doByName) != 0) {
- fontPtr = (StringPtr) (wictPtr + data.fontNum);
- BlockMove (fontPtr, &fontName, 256);
- GetFNum (fontName, &data.fontNum);
- }
- }
- if ((header & doFace) == 0) {
- data.typeStyle = 0;
- }
- if ((header & doSize) == 0) {
- data.typeSize = 0;
- }
- if ((header & doXferMode) == 0) {
- data.xferMode = srcCopy;
- }
- TextFont (data.fontNum);
- TextFace (data.typeStyle);
- TextMode (data.xferMode);
- TextSize (data.typeSize);
- textJust = data.just;
- }
- } /* SetWFont */
-
- /*----------*/
- WindowPtr GetWindow (short windowID)
- {
- if (sysConfig.hasColorQD) {
- return (GetNewCWindow (windowID, NULL, (WindowPtr) -1L));
- } else {
- return (GetNewWindow (windowID, NULL, (WindowPtr) -1L));
- }
- } /* GetWindow */
-
- /*----------*/
- ListHandle NewV1List (Rect bounds,
- WindowPtr parentWindow)
- {
- Rect listBounds;
- Rect dataBounds;
- Point cSize;
- ListHandle list;
-
- listBounds = bounds;
- listBounds.right = listBounds.right - 15; /*for scroll bar*/
- SetRect (&dataBounds, 0, 0, 1, 0); /*one column, no rows*/
- SetPt (&cSize, listBounds.right - listBounds.left, 0);
- list = LNew (&listBounds, /*dialog item's box*/
- &dataBounds, /*one column, no rows*/
- cSize, /*cell size: full width, standard height*/
- 0, /*procid - standard text list*/
- parentWindow, /*parent window*/
- false, /*draw it*/
- false, /*has no grow*/
- false, /*no horizontal scroll*/
- true); /*vertical scroll*/
- (**list).selFlags = lOnlyOne + lNoNilHilite;
- return (list);
- } /*NewV1List*/
-
- /*----------*/
- Boolean GetListChoice (short *choice,
- ListHandle list)
- {
- Boolean result;
- Cell selectedCell;
-
- SetPt (&selectedCell, 0, 0);
- if (LGetSelect (true, &selectedCell, list)) {
- *choice = selectedCell.v;
- result = true;
- } else {
- *choice = -1;
- result = false;
- }
-
- return (result);
- } /*GetListChoice*/
-
- /*----------*/
- void SetListChoice (short choice,
- ListHandle list)
- {
- Cell selectedCell;
-
- SetPt (&selectedCell, 0, choice);
- LSetSelect (true, selectedCell, list);
- } /*SetListChoice*/
-
- /*----------*/
- void GetListRow (Str255 data,
- short index,
- ListHandle list)
- {
- Cell selectedCell;
- short dataLen;
-
- SetPt (&selectedCell, 0, index);
- dataLen = 255; /*var parameter to LGetCell*/
- LGetCell (&data [1], &dataLen, selectedCell, list);
- data [0] = (char) dataLen;
- } /*GetListRow*/
-
- /*----------*/
- void SetListRow (Str255 data,
- short index,
- ListHandle list)
- {
- Cell selectedCell;
-
- SetPt (&selectedCell, 0, index);
- LSetCell (&data [1], data [0], selectedCell, list);
- } /*SetListRow*/
-
- /*----------*/
- void AddToList (Str255 data,
- ListHandle list)
- {
- short newRow;
-
- #define maxint 32767
-
- newRow = LAddRow (1, maxint, list);
- SetListRow (data, newRow, list);
- } /*AddToList*/
-
- /*----------*/
- void DrawList (ListHandle list)
- {
- PenState savePen;
- Rect frame;
-
- GetPenState (&savePen);
- PenNormal ();
- frame = (**list).rView;
- InsetRect (&frame, -1, -1);
- FrameRect (&frame);
- SetPenState (&savePen);
- LUpdate ((**list).port->visRgn, list);
- } /*DrawList*/
-
- /*----------*/
- void TextIDBox (short textID,
- Rect bounds)
- {
- Handle text;
-
- text = GetResource ('TEXT', textID);
- if (text != NULL) {
- LoadResource (text);
- HLock (text);
- TextBox (&(**text), GetHandleSize (text), &bounds, textJust);
- HUnlock (text);
- }
- } /*TextIDBox*/
-
- /*----------*/
- void PlotIconID (short iconID,
- Rect bounds)
- {
- Handle icon;
-
- icon = GetIcon (iconID);
- if (icon != NULL) {
- LoadResource (icon);
- PlotIcon (&bounds, icon);
- }
- } /*PlotIconID*/
-
- /*----------*/
- void DrawPictureID (short pictID,
- Rect bounds)
- {
- PicHandle pict;
-
- pict = GetPicture (pictID);
- if (pict != NULL) {
- LoadResource ((Handle) (pict));
- DrawPicture (pict, &bounds);
- }
- } /*DrawPictureID*/
-
- /*----------*/
- void DrawGrayLine (Rect bounds)
- {
- PenState savePen;
-
- GetPenState (&savePen);
- PenNormal ();
- #ifdef dangerousPattern
- PenPat (qd.gray);
- #else
- PenPat (&qd.gray);
- #endif
- MoveTo (bounds.left, bounds.top);
- LineTo (bounds.right - 1, bounds.bottom - 1);
- SetPenState (&savePen);
- } /*DrawGrayLine*/
-
- /*----------*/
- static void DrawTriangle (const Rect *bounds);
- static void DrawTriangle (const Rect *bounds)
- {
- PolyHandle arrowTriangle;
-
- arrowTriangle = OpenPoly ();
- MoveTo (bounds->right - 15, bounds->top + 5);
- Line (5, 5);
- Line (5, -5);
- Line (-10, 0);
- ClosePoly ();
- #ifdef dangerousPattern
- FillPoly (arrowTriangle, qd.black);
- #else
- FillPoly (arrowTriangle, &qd.black);
- #endif
- KillPoly (arrowTriangle);
- } /*DrawTriangle*/
-
- /*----------*/
- void UpdatePopup (Rect bounds,
- short menuID,
- short choice)
- {
- MenuHandle menu;
- Str255 menuItem;
- Rect textRect;
-
- menu = (MenuHandle) (GetResource ('MENU', menuID));
- if (menu != NULL) {
- GetItem (menu, choice, menuItem);
- textRect = bounds;
- textRect.left = textRect.left + 12; /*space for checkmark*/
- textRect.right = textRect.right - 20; /*space for triangle*/
- TextBox (&menuItem [1], menuItem [0], &textRect, teJustLeft);
- }
-
- DrawTriangle (&bounds);
-
- bounds.right = bounds.right - 1;
- bounds.bottom = bounds.bottom - 1;
- FrameRect (&bounds);
- MoveTo (bounds.right, bounds.top + 2);
- LineTo (bounds.right, bounds.bottom);
- LineTo (bounds.left + 2, bounds.bottom);
- } /*UpdatePopup*/
-
- /*----------*/
- void TrackPopup (Rect bounds,
- short menuID,
- short *choice)
- {
- MenuHandle menu;
- Point corner;
- long result;
- Rect triangleRect;
-
- menu = (MenuHandle) (GetResource ('MENU', menuID));
- if (menu != NULL) {
- InsertMenu (menu, -1);
- triangleRect.top = bounds.top + 5;
- triangleRect.left = bounds.right - 18;
- triangleRect.bottom = triangleRect.top + 7;
- triangleRect.right = triangleRect.left + 13;
- EraseRect (&triangleRect);
- corner = topLeft (bounds);
- LocalToGlobal (&corner);
- CheckItem (menu, *choice, true);
- result = PopUpMenuSelect (menu, corner.v, corner.h + 1, *choice);
- CheckItem (menu, *choice, false);
- DeleteMenu (menuID);
- InvalRect (&triangleRect); /*because we always erase triangleRect*/
- if ((HiWord (result) != 0) && (LoWord (result) != *choice)) {
- *choice = LoWord (result);
- InsetRect (&bounds, 1, 1);
- InvalRect (&bounds);
- }
- }
- } /*TrackPopup*/
-
- /*----------*/
- Boolean TrackButton (ControlHandle button,
- Point mousePos)
- {
- return (TrackControl (button, mousePos, NULL) != 0);
- } /*TrackButton*/
-
- /*----------*/
- void TrackCheck (ControlHandle checkBox,
- Point mousePos,
- Boolean *checked)
- {
- if (TrackControl (checkBox, mousePos, NULL) != 0) {
- *checked = !*checked;
- SetCtlValue (checkBox, *checked);
- }
- } /*TrackCheck*/
-
- /*----------*/
- void TrackRadio (ControlHandle radio,
- Point mousePos,
- short *choice)
- {
- long refCon;
- short group;
- ControlHandle control;
-
- if (TrackControl (radio, mousePos, NULL) != 0) {
- refCon = GetCRefCon (radio);
- group = HiWord (refCon);
- *choice = LoWord (refCon);
- control = ((WindowPeek) qd.thePort)->controlList;
- while (control != NULL) {
- if ((**control).contrlDefProc == (**radio).contrlDefProc) {
- refCon = GetCRefCon (control);
- if (HiWord (refCon) == group) {
- SetCtlValue (control, 0);
- }
- }
- control = (**control).nextControl;
- } /*while*/
- SetCtlValue (radio, 1);
- }
- } /*TrackRadio*/
-
- /*----------*/
- void TrackMulti (ControlHandle multi,
- Point mousePos,
- short *value)
- {
- if (TrackControl (multi, mousePos, NULL) != 0) {
- if (*value == GetCtlMax (multi)) {
- *value = GetCtlMin (multi);
- } else {
- (*value)++;
- }
- SetCtlValue (multi, *value);
- }
- } /*TrackMulti*/
-
- /*----------*/
- void TrackPalette (ControlHandle palette,
- Point mousePos,
- short *choice)
- {
- if (TrackControl (palette, mousePos, NULL) != 0) {
- *choice = GetCtlValue (palette);
- }
- } /*TrackPalette*/
-
- /*----------*/
- void EnableControl (ControlHandle theControl,
- Boolean active)
- {
- if (theControl != NULL) {
- if (active) {
- HiliteControl (theControl, 0);
- } else {
- HiliteControl (theControl, 255);
- }
- }
- } /*EnableControl*/
-
- /*----------*/
- /* for backwards compatibility:*/
- /*----------*/
- void HiliteScroll (ControlHandle scroll,
- Boolean active)
- {
- EnableControl (scroll, active);
- } /*HiliteScroll*/
-
- /* WindowAids */
-